<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="用户" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类别" prop="categoryId">
        <treeselect
          v-model="queryParams.categoryId"
          :options="categoryOptions"
          :normalizer="normalizer"
          :show-count="true"
          placeholder="选择分类"
          style="width: 130px"
        />
      </el-form-item>
      <el-form-item label="内容" prop="content">
        <el-input
          v-model="queryParams.content"
          placeholder="请输入发表的内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择状态"
          clearable
        >
          <el-option
            v-for="dict in campusContentStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择类型"
          clearable
        >
          <el-option
            v-for="dict in campusContentTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="匿名" prop="isAnonymous">
        <el-select
          v-model="queryParams.isAnonymous"
          placeholder="请选择是否匿名"
          clearable
        >
          <el-option
            v-for="dict in campusAnonymousOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <!-- v-hasPermi="['campus:content:add']" -->
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <!-- v-hasPermi="['campus:content:edit']" -->
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="contentList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户昵称" align="center" prop="params.nickName" />
      <el-table-column label="类别" align="center" prop="params.categoryName" />
      <el-table-column
        label="内容"
        align="center"
        prop="content"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag
            :options="campusContentStatusOptions"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag
            :options="campusContentTypeOptions"
            :value="scope.row.type"
          />
        </template>
      </el-table-column>
      <el-table-column label="匿名" align="center" prop="isAnonymous">
        <template slot-scope="scope">
          <dict-tag
            :options="campusAnonymousOptions"
            :value="scope.row.isAnonymous"
          />
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            >详细</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改校园墙内容对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="500px"
      append-to-body
      :before-close="cancel"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="分类" prop="categoryId">
          <!-- <el-input v-model="form.categoryId" placeholder="分类" /> -->
          <treeselect
            v-model="form.categoryId"
            :options="categoryOptions"
            :disableBranchNodes="true"
            :normalizer="normalizer"
            :show-count="true"
            placeholder="选择分类"
          />
        </el-form-item>
        <el-form-item label="内容" prop="content">
          <el-input
            v-model="form.content"
            type="textarea"
            placeholder="请输入发表的内容"
          />
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in campusContentStatusOptions"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
              >{{ dict.dictLabel }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="类型" prop="type">
          <el-select v-model="form.type" placeholder="请选择类型">
            <el-option
              v-for="dict in campusContentTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="匿名" prop="isAnonymous">
          <el-select v-model="form.isAnonymous" placeholder="请选择匿名">
            <el-option
              v-for="dict in campusAnonymousOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="选择图片"
          prop="selectPicture"
          v-show="form.type == 1"
        >
          <el-button
            type="text"
            @click="selectPictureClick()"
            :disabled="disabled.picture"
          >
            <svg-icon
              class="woo-font woo-font--emotico"
              style="width: 18px; height: 18px"
              icon-class="picture"
            />
            <span class="iconbed-text">图片</span>
          </el-button>
        </el-form-item>
        <el-form-item
          label="选择视频"
          prop="selectVideo"
          v-show="form.type == 2"
        >
          <el-button
            type="text"
            @click="selectVideoClick()"
            :disabled="disabled.video"
          >
            <svg-icon
              class="woo-font woo-font--emotico"
              style="width: 18px; height: 18px"
              icon-class="video"
            />
            <span class="iconbed-text">视频</span>
          </el-button>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
      <el-upload
        style="height: 15x"
        :headers="upload.headers"
        v-show="upload.show"
        ref="upload"
        :limit="upload.limit"
        :action="upload.action"
        :show-file-list="true"
        :list-type="upload.listType"
        :accept="upload.accept"
        :auto-upload="false"
        :file-list="fileList"
        :on-change="handleChange"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :on-exceed="handleExceed"
        :on-success="handleSuccess"
        :on-error="handleError"
      >
        <button id="uploadBtn" v-show="false"></button>
      </el-upload>
      <!-- 预览弹窗 -->
      <el-dialog :visible.sync="previewVisible" title="图片预览">
        <img :src="previewImageUrl" style="width: 100%" />
      </el-dialog>
    </el-dialog>

    <!-- 调度校园墙内容详细 -->
    <el-dialog
      title="帖子详细"
      :visible.sync="viewOpen"
      width="700px"
      append-to-body
    >
      <el-form ref="form" :model="form" label-width="100px" size="mini">
        <el-row>
          <el-col :span="8">
            <el-form-item label="头像："
              ><image-preview :src="this.contentParams.avatar"> </image-preview
            ></el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="用户昵称：">{{
              contentParams.nickName
            }}</el-form-item>
            <el-form-item label="用户账户：">{{
              contentParams.userName
            }}</el-form-item>
            <el-form-item label="分类：">{{
              contentParams.categoryName
            }}</el-form-item>
          </el-col>

          <!-- <el-col :span="8">
            <el-form-item label="标签：">
              <li v-for="item in form.tags">{{ item.tagName }}</li>
            </el-form-item>
          </el-col> -->
          <el-col :span="24">
            <el-form-item label="内容：" style="white-space: pre-wrap">{{
              form.content
            }}</el-form-item>
          </el-col>
          <el-col :span="24" v-if="form.type == 1">
            <el-form-item label="图片：">
              <div
                class="picture_item"
                v-for="(item, key) in form.fileUrl"
                :key="key"
              >
                <image-preview
                  style="border-radius: 10px; width: 25%; aspect-ratio: 1/1"
                  :src="item"
                >
                </image-preview>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="form.type == 2">
            <el-form-item label="视频：">
              <div
                class="picture_item"
                v-for="(item, key) in form.fileUrl"
                :key="key"
              >
                <el-link
                  :underline="false"
                  :href="handleUrl(item)"
                  target="_blank"
                  >点击跳转</el-link
                >
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="viewOpen = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listContent,
  getContent,
  delContent,
  addContent,
  updateContent,
} from "@/api/campus/content";

import { listSelectCategory, listCategory } from "@/api/campus/category";
import { deleteFile } from "@/api/campus/file";
import { isExternal } from "@/utils/validate";
import { getToken } from "@/utils/auth";

import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import Treeselect from "@riophae/vue-treeselect";

export default {
  name: "Content",
  // dicts: ["campusContentStatusOptions", "campusContentTypeOptions", "campusAnonymousOptions"],
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      //分类树选项
      categoryOptions: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 校园墙内容表格数据
      contentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否显示详细的弹出层
      viewOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        categoryId: null,
        content: null,
        status: null,
        type: null,
        isAnonymous: null,
      },
      //其他参数
      contentParams: {
        nickName: "",
        userName: "",
        avatar: "",
        categoryName: "",
      },
      //删除图片参数
      deleteParams: {
        fileId: null,
        fileName: null,
        type: null,
      },
      //上传参数
      upload: {
        show: false,
        action: "",
        limit: 3,
        accept: "",
        listType: "",
        headers: {},
      },
      //1图片,2视频
      selectType: 0,
      fileCount: 0,
      fileList: [],
      previewVisible: false, // 控制弹窗显示
      previewImageUrl: "", // 预览图片的 URL
      //禁用
      disabled: {
        picture: false,
        video: false,
      },
      //状态数据字典
      campusContentStatusOptions: [],
      campusContentTypeOptions: [],
      campusAnonymousOptions: [],
      fileChangeList: [],
      // 表单参数
      form: {
        contentId: null,
        userId: null,
        categoryId: null,
        content: null,
        status: 0,
        type: null,
        fileNumber: null,
        isAnonymous: null,
        delFlag: null,
        createTime: null,
        createUser: null,
        updateTime: null,
        updateUser: null,
        fileList: [],
        files: null,
        fileUrl: null,
      },
      // 表单校验
      rules: {
        categoryId: [
          { required: true, message: "分类不能为空", trigger: "blur" },
        ],
        content: [{ required: true, message: "内容不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getList();
    this.reset();
    this.getTreeselect();
    this.getDictsList();
    this.upload.headers["Authorization"] = "Bearer " + getToken();
  },
  methods: {
    /** 查询校园墙内容列表 */
    getList() {
      this.loading = true;
      listContent(this.queryParams).then((response) => {
        this.contentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //选择图片
    selectPictureClick() {
      console.log("选择图片");
      //   this.$refs.uploadBtn.$el.click();
      //   this.$refs.uploadBtn.dispatchEvent(new MouseEvent('click'));
      this.upload.show = true;
      this.upload.action = this.handleCampusUrl("/campus/imageUpload");
      this.upload.limit = 3;
      this.upload.accept = "image/*";
      this.upload.listType = "picture-card";
      this.selectType = 1;
      document.getElementById("uploadBtn").click();
      this.upload.show = true;
    },
    selectVideoClick() {
      console.log("选择视频");
      //   this.$refs.uploadBtn.$el.click();
      //   this.$refs.uploadBtn.dispatchEvent(new MouseEvent('click'));
      this.upload.show = true;
      this.upload.action = this.handleCampusUrl("/campus/videoUpload");
      this.upload.limit = 1;
      this.upload.accept = "video/*";
      this.upload.listType = "text";
      this.selectType = 2;
      document.getElementById("uploadBtn").click();
      this.upload.show = true;
    },
    // 获取字典字段的值
    getDictsList() {
      this.getDicts("campus_content_status").then((response) => {
        // console.log(response)
        this.campusContentStatusOptions = response.data;
      });
      this.getDicts("campus_content_type").then((response) => {
        // console.log(response)
        this.campusContentTypeOptions = response.data;
      });
      this.getDicts("campus_anonymous").then((response) => {
        this.campusAnonymousOptions = response.data;
      });
    },
    /** 转换菜单数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.categoryId,
        label: node.categoryName,
        children: node.children,
      };
    },
    /** 查询下拉树结构 */
    getTreeselect() {
      listSelectCategory().then((response) => {
        this.categoryOptions = this.handleTree(response.data, "categoryId");
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.resetUpload();
    },
    // 表单重置
    reset() {
      this.form = {
        contentId: null,
        userId: null,
        categoryId: null,
        content: null,
        status: 0,
        type: null,
        fileNumber: null,
        isAnonymous: null,
        delFlag: null,
        createTime: null,
        createUser: null,
        updateTime: null,
        updateUser: null,
      };
      this.resetForm("form");
    },
    resetUpload() {
      // this.upload = {
      //   show: false,
      //   action: "",
      //   limit: 3,
      //   accept: "",
      //   listType: "",
      //   headers: {},
      // };
      // //文件移除
      // this.checkBtn();
      // this.$refs.upload.clearFiles(); // 清空文件列表
      if (
        this.$refs.upload &&
        typeof this.$refs.upload.clearFiles === "function"
      ) {
        this.$refs.upload.clearFiles();
      }
      this.upload.show = false;
      this.disabled.picture = false;
      this.disabled.video = false;
      this.fileList = [];
      this.form.fileList = [];
      this.fileChangeList = [];

      // this.resetForm("upload");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.contentId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加校园墙内容";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.resetUpload();
      // this.fileList = [];

      const contentId = row.contentId || this.ids;
      getContent(contentId).then((response) => {
        this.form = response.data;
        // console.log(this.form);
        if (this.form.type === 1) {
          // this.disabled.video = true;
          // this.selectType = 1;
          // console.log(this.handleCampusUrl("/campus/imageUpload"))
          this.upload.action = this.handleCampusUrl("/campus/imageUpload");
          // console.log(this.upload.action);
          this.upload.limit = 3;
          this.upload.accept = "image/*";
          this.upload.listType = "picture-card";
          this.upload.show = true;
        } else if (this.form.type === 2) {
          // this.disabled.picture = true;
          // this.selectType = 2;
          this.upload.action = this.handleCampusUrl("/campus/videoUpload");
          this.upload.limit = 1;
          this.upload.accept = "video/*";
          this.upload.listType = "text";
          this.upload.show = true;
        } else {
          this.upload.show = false;
        }
        this.open = true;
        this.title = "修改校园墙内容";
        // console.log(this.form.fileUrl)

        //处理返回来的图片
        if (this.form.files != null) {
          // 将后端数据转换为 file-list 格式
          this.fileList = this.form.files.map((image) => ({
            url: this.handleUrl(image.fileUrl), // 图片 URL
            name: image.fileName,
            // status: "success", // 状态为成功，表示已上传
            id: image.fileId
          }));
          // this.upload.listType = "picture-card";
        }
        this.fileCount = this.fileList.length;
        // this.form.fileList = this.fileList;
        // this.upload.show = true;
        // console.log(this.fileList);
      });
    },
    /** 提交按钮 */
    submitForm() {
      console.log("触发表单提交");
      this.form.fileList = [];
      // this.form.fileList = this.fileList;
      // for (let file of this.fileList) {
      //   // console.log(file.response);
      //   if (file.response !== undefined && file.response.code == 200) {
      //     this.form.fileList.push(file.response.data.fileId);
      //   } else {
      //     console.log("禁止");
      //   }
      // }

      this.form.fileList = this.fileList.map((image) => ({
        fileUrl: image.url, // 图片 URL
        fileName: image.name,
        // status: "success", // 状态为成功，表示已上传
        fileId: image.id,
      }));
      console.log("fileList");
      console.log(this.fileList);
      console.log("form.fileList");
      console.log(this.form.fileList);

      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.contentId != null) {
            updateContent(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addContent(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
      this.resetUpload();
      this.fileList = [];
      this.form.fileList = [];
      this.fileChangeList = [];
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.viewOpen = true;
      this.form = row;
      this.contentParams = row.params;
      // console.log(this.handleUrl(this.contentParams.avatar))
    },
    handleUrl(url) {
      if (!url) {
        return;
      }
      let real_src = url.split(",")[0];
      if (isExternal(real_src)) {
        return real_src;
      }
      // console.log(process.env.VUE_APP_BASE_API)
      return process.env.VUE_APP_BASE_API + real_src;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const contentIds = row.contentId || this.ids;
      this.$confirm(
        '是否确认删除校园墙内容编号为"' + contentIds + '"的数据项？',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delContent(contentIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/content/export",
        {
          ...this.queryParams,
        },
        `content_${new Date().getTime()}.xlsx`
      );
    },
    //文件移除
    handleRemove(file, fileList) {
      console.log("触发文件移除");
      console.log(file, fileList);
      // this.fileList = fileList; // 更新文件列表
      this.fileChangeList = fileList;

      // console.log(this.form.files);
      
      this.deleteParams.fileId = file.id;
      this.deleteParams.fileName = file.name;
      this.deleteParams.type = this.form.type;

      if(fileList.length > 0) {
        this.fileList = fileList.map(item => ({
          id: item.id,          // 如果 fileId 可能不存在，给默认值
          name: item.name,
          url: item.url,                // 添加新字段（旧数据没有的）
        }));
      }else {
        this.fileList = [];
      }

      deleteFile(this.deleteParams).then((response) => {
        if (response.code === 200) {
          this.$message.success("删除成功");
        } else {
          this.$message.error("删除失败");
        }
      });

      this.checkBtn();
    },
    //点击文件列表中已上传的文件时的钩子
    handlePreview(file) {
      console.log("触发文件列表上传时候钩子");
      console.log(file);
      if (this.form.type === 1) {
        // 获取图片的 URL 或 Base64 数据
        this.previewImageUrl = file.url || URL.createObjectURL(file.raw);
        this.previewVisible = true; // 显示弹窗
      }else {
        window.location.href = file.url;
      }
    },
    //上传成功
    handleSuccess(response, file, fileList) {
      console.log("上传成功");
      console.log(response, file, fileList);
      this.fileChangeList = fileList;
      if (response.code != 200) {
        fileList.splice(fileList.length - 1, 1);
        this.$message.warning(response.msg);
        setTimeout(() => {
          this.$message.error("上传失败，请重新上传");
        }, 1000);
      }
      // 假设服务器返回图片 URL
      this.fileList.push({
        url: this.handleUrl(response.data.url),
        name: file.name,
        id: file.response.data.fileId,
      });
      // this.form.fileList = this.fileList;
      // console.log(this.fileList);
      this.checkBtn();
    },
    handleError(err, file, fileList) {
      this.$message.error("上传失败");
      this.checkBtn();
    },
    //文件改变
    handleChange(file, fileList) {
      console.log("触发文件改变");
      // console.log(file, fileList);
      // this.fileList = fileList;
      this.fileChangeList = fileList;
      let fileNum = this.fileChangeList.length;
      // this.fileCount = fileNum;
      //添加文件
      if (this.fileCount <= fileNum) {
        // console.log(file.raw.type.startsWith("image"));
        if (file.raw.type.startsWith("image")) {
          this.disabled.video = true;
          this.selectType = 1;
          // console.log(this.handleCampusUrl("/campus/imageUpload"))
          this.upload.action = this.handleCampusUrl("/campus/imageUpload");
          // console.log(this.upload.action);
          this.upload.limit = 3;
          this.upload.accept = "image/*";
          this.upload.listType = "picture-card";
        } else {
          this.disabled.picture = true;
          this.selectType = 2;
          this.upload.action = this.handleCampusUrl("/campus/videoUpload");
          this.upload.limit = 1;
          this.upload.accept = "video/*";
          this.upload.listType = "text";
        }
        this.validated(file);
        //上传文件
        this.$refs.upload.submit();
      }

      if (fileNum > 0) {
        this.upload.show = true;
      }
      // this.checkBtn();
    },
    handleExceed(files, fileList) {
      this.$message.warning(`上传数量超过限制`);
    },
    //验证文件类型
    validated(file) {
      // 若不符合类型，则让当前上传的文件去除掉即可，即从上传对列删除本次上传
      const size = file.size / 1024 / 1024;
      if (this.selectType == 1) {
        if (!file.raw.type.startsWith("image")) {
          this.$message.warning(`请选择图片`);
          this.fileList.splice(this.fileList.length - 1, 1);
        }

        if (size > 5) {
          this.fileList.splice(this.fileList.length - 1, 1);
          this.$message.warning("上传的图片大小不能超过 5MB!");
        }
      } else {
        if (!file.raw.type.startsWith("video")) {
          this.$message.warning(`请选择视频`);
          this.fileList.splice(this.fileList.length - 1, 1);
        }
        if (size > 20) {
          this.fileList.splice(this.fileList.length - 1, 1);
          this.$message.warning("上传的视频大小不能超过 20MB!");
        }
      }
    },
    checkBtn() {
      if (this.fileList.length == 0) {
        this.upload.show = false;
        this.disabled.picture = false;
        this.disabled.video = false;
      }
    },
  },
};
</script>

<style scoped>
.picture_item {
  display: inline;
  padding-left: 0.25rem;
  padding-top: 0.25rem;
}
</style>